@extends('layouts.admin_common') @section('content')
@if(app('env')=='production')
<script src="{{ secure_asset('js/corp.js') }}"></script>
@else
<script src="{{ asset('js/corp.js') }}"></script>
@endif
<div class="breadcrumbs_container">
	{{Breadcrumbs::render('admin.corp_master') }}</div>
<div class="system_tab_line"></div>
<script type="text/javascript">
function saveUser(){
	if ($("#staff_name").val()==""){
		alert("担当者名を入力してください。");
		//$('#myAlert').modal('show');
		return;
	}
	if ($("#staff_kana").val()==""){
		alert("担当者カナを入力してください。");
		//$('#myAlert').modal('show');
		return;
	}
	 var formData = new FormData();
	 if ($("#staff_id") != undefined && $("#staff_id").val()  != undefined) {
		 formData.append("staff_id", $("#staff_id").val());
	 }

     formData.append("staff_name", $("#staff_name").val());
     formData.append("staff_kana", $("#staff_kana").val());
     formData.append("staff_tel", $("#staff_tel").val());
     formData.append("staff_mail", $("#staff_mail").val());
     formData.append("corp_id",$("#corp_id").val());

     if ($("#is_send_mail").prop("checked") == true) {
    	 formData.append("is_send_mail", 1);
     } else {
    	 formData.append("is_send_mail", 0);
     }

	 $.ajax({
        headers: {
        	'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        type: 'POST',
        url: '../comp/save_staff' ,
        data: formData ,
        processData:false,
        mimeType:"multipart/form-data",
        contentType: false,
        cache: false,
        success:function(data){
        	alert("担当者を登録しました。画面をリロードしてください。");
        	$('#addUserModel').modal('hide');
        },
        error:function(err){
        	  alert(err.status);
        	  $('#addUserModel').modal('hide');
        }
    });
}
function addStaff(){
	$("#staff_id").val("");
	$("#staff_name").val("");
	$("#staff_kana").val("");
	$("#staff_tel").val("");
	$("#staff_mail").val("");
	$("#is_send_mail").prop("checked", false);
	$('#addUserModel').modal('show');
}
function editStaff(id, name, kana, tel, mail, send){
	$("#staff_id").val(id);
	$("#staff_name").val(name);
	$("#staff_kana").val(kana);
	$("#staff_tel").val(tel);
	$("#staff_mail").val(mail);
	if(send) {
		$("#is_send_mail").prop("checked", true);
	} else {
		$("#is_send_mail").prop("checked", false);
	}

	$('#addUserModel').modal('show');
}
</script>

<body>
	<div id="outDiv">
		<form id="compForm" class="form-inline" method="post">
			<table class="table table-condensed">
			<col width="160px">
			<col width="*">
			<col width="160px">
			<col width="*">
				<tr>
				<td>会社名</td>
				<td><input type="hidden" id="corp_id" name="CorpMaster[corp_id]"
					value="{{$allInfo[0]->corp_id}}"> <input type="text"
					class="form-control input-lg" placeholder="会社名" name="CorpMaster[corp_name]"
					value="{{$allInfo[0]->corp_name}}">

				<td>ログインID</td>
				<td>
				<?php if($allInfo[0]->corp_id!==""):?>
				{{$allInfo[1][0]}}
				<input type="hidden" class="form-control" placeholder="" name="userMaster[user_id]" value="{{$allInfo[1][1]}}" >
				<?php endif;?>
				</td>
			</tr>
			<tr>
				<td>会社名カナ</td>
				<td><input type="text" class="form-control" placeholder="会社名カナ"
					name="CorpMaster[corp_catelogue]"
					value="{{$allInfo[0]->corp_catelogue}}"></td>
				<td>ログインＰass</td>
				<td>
				<?php if($allInfo[0]->corp_id!==""):?>
				<input type="text" class="form-control" placeholder="" name="userMaster[password]" value="{{$allInfo[1][2]}}">
				<?php endif;?>
				</td>
			</tr>
			<tr>
				<td>郵便番号</td>
				<td><input type="text" class="form-control" placeholder="郵便番号" checked="checked"
					name="CorpMaster[corp_postcode]"
					value="{{$allInfo[0]->corp_postcode}}" onblur="onCheckPost(this)"></td>
			</tr>
			<tr>
				<td>住所</td>
				<td><input type="text" class="form-control" placeholder="住所" checked="checked"
					name="CorpMaster[corp_adress]" value="{{$allInfo[0]->corp_adress}}"></td>
			</tr>
			<tr>
				<td>住所（ビル名）</td>
				<td><input type="text" class="form-control" placeholder="" name="CorpMaster[buil_name]" value="{{$allInfo[0]->buil_name}}"></td>
			</tr>
			<tr>
				<td>会社TEL</td>
				<td><input type="text" class="form-control" placeholder="会社TEL" checked="checked"
					name="CorpMaster[corp_tel]" value="{{$allInfo[0]->corp_tel}}" onblur="onCheckPhone(this)"></td>
				<td>会社FAX</td>
				<td><input type="text" class="form-control" placeholder="会社FAX" checked="checked"
					name="CorpMaster[corp_fax]" value="{{$allInfo[0]->corp_fax}}" onblur="onCheckPhone(this)"></td>
			</tr>
			<tr>
				<td>代表Mail</td>
				<td><input type="text" class="form-control" placeholder="代表Mail" checked="checked"
					name="CorpMaster[corp_mail]" value="{{$allInfo[0]->corp_mail}}" onblur="onCheckEmail(this)"></td>
			</tr>
			<tr>
				<td>代表担当者</td>
				<td><input type="text" class="form-control" placeholder="代表担当者"
					name="CorpMaster[corp_stuff]" value="{{$allInfo[0]->corp_stuff}}"></td>
				<td>担当者TEL</td>
				<td><input type="text" class="form-control" placeholder="担当者TEL"
					name="CorpMaster[corp_stuff_telephone]" value="{{$allInfo[0]->corp_stuff_telephone}}"
					value="" onblur="onCheckPhone(this)"></td>
			</tr>
			<tr>
				<td>担当者カナ</td>
				<td><input type="text" class="form-control" placeholder="担当者カナ"
					name="CorpMaster[corp_stuff_kana]"
					value="{{$allInfo[0]->corp_stuff_kana}}"></td>
				<td>担当Ｍail</td>
				<td><input type="text" class="form-control" placeholder="担当Ｍail"
					name="CorpMaster[corp_stuff_mail]"
					value="{{$allInfo[0]->corp_stuff_mail}}" onblur="onCheckEmail(this)"></td>
			</tr>
			<tr>
			<td>請求方法</td>
			<td><select name="bill_method" id="bill_method" class="form-control" >
			<option value="1">個別請求</option>
			<option value="2">纏めて請求</option>
			</select></td>

		</tr>
			</table>
			<?php if ($allInfo[0]->corp_id!==""):?>
			<table class="table table-condensed">
				<tr><td>担当者</td><td><input type="button" value="追加"
					class="btn btn-primary button_normal" data-toggle="modal" onclick="addStaff()"
						 /></td></tr>
			</table>
			<div>

			<table class="table table-condensed">
			<tr>
				<td>担当者名</td>
				<td>担当者カナ</td>
				<td>電話番号</td>
				<td>メール</td>
				<td>メール送信</td>
				<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
			</tr>
			<tr>@foreach ($staffInfos as $staffInfo)
			<tr>
				<td>{{$staffInfo->staff_name}}</td>
				<td>{{$staffInfo->staff_kana}}</td>
				<td>{{$staffInfo->tel}}</td>
				<td>{{$staffInfo->mail}}</td>
				<td><?php if($staffInfo->is_send_mail){echo "送信";}?></td>
				<td><input type="button" value="修正" class="btn btn-primary button_normal" onclick="editStaff('{{$staffInfo->staff_id}}','{{$staffInfo->staff_name}}','{{$staffInfo->staff_kana}}','{{$staffInfo->tel}}','{{$staffInfo->mail}}','{{$staffInfo->is_send_mail}}')" />
					<input type="button" value="削除" class="btn btn-primary button_normal" onclick="onSubmit('delete','{{$staffInfo->staff_id}}')" /></td>
			</tr>
			@endforeach
		</table>
<?php endif;?>
				<table border="0" cellspacing="0" style="width: 1300px;">
					<tr>
						<td><input type="button" value="保存"
							class="pure-button pure-button-primary button_normal"
							onclick="onSubmit('create')" /></td>
						<td><input type="button" value="キャンセル"
							class="pure-button pure-button-primary button_normal"
							onclick="location.href='../home'" /></td>
						<td><input type="button" value="削除"
							class="pure-button pure-button-primary button_normal"
							onclick="onSubmit('delete')" /></td>
						<td><input type="button" value="Csv取込"
							class="pure-button pure-button-primary button_normal"
							onclick="onSubmit('export')" /></td>

				</table>
			</div>
			<div>@if(isset($success)) {{$success}} @endif</div>
			<div>@if(isset($error)) {{$error}} @endif</div>
			<input type="hidden" name="_token" id="csrf-token"
				value="{{ Session::token() }}" />
		</form>
	</div>
	<div class="modal fade" id="addUserModel" tabindex="-1" role="dialog" aria-labelledby="addUserLabel" aria-hidden="true">
	  <div class="modal-dialog" role="document">
	    <div class="modal-content">
	      <div class="modal-header">
	        <h5 class="modal-title" id="addUserLabel">担当者追加</h5>
	      </div>
	      <div class="modal-body">
	      <table class="table table-condensed">
	      <tr><td>担当者名</td>
	      		<td><input type="hidden" name="staff_id" id="staff_id">
	      			<input type="text" class="form-control" placeholder="ユーザ名"
	      			name="staff_name" checked="checked" id="staff_name"
	      		></td>
	      	</tr>
	      	<tr>
	      		<td>担当者カナ</td>
	      		<td>
	      			<input type="text" class="form-control" placeholder="ユーザカナ" id="staff_kana"  checked="checked" ></td>
	      	</tr>
	      	<tr>
	      		<td>電話番号</td>
	      		<td><input type="text" class="form-control" placeholder="TEL" id="staff_tel" ></td>
	      	</tr>
	      	<tr>
	      		<td>メールアドレス</td>
	      		<td><input type="text" class="form-control" placeholder="MAIL" name="staff_mail" id = "staff_mail"></td>
	      	</tr>
	      	<tr>
	      		<td>メール送信</td>
	      		<td><input type="checkbox" class="form-control"  name="is_send_mail" /></td>
	      	</tr>
	      </table>
	      </div>

	      <div class="modal-footer">
	        <button type="button" class="btn btn-secondary" data-dismiss="modal">閉じる</button>
	        <button type="button" class="btn btn-primary" onclick="saveUser()">保存</button>
	      </div>
	    </div>
	  </div>
	</div>

</body>
</html>
@endsection
